﻿using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Topthink.Ruitu.QuestionBank.Localization;
using Topthink.Ruitu.QuestionBank.Permissions;
using Topthink.Ruitu.QuestionBank.Web.Menus;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;

namespace Topthink.Ruitu.QuestionBank.Web
{
    [DependsOn(
        typeof(QuestionBankHttpApiModule),
        typeof(AbpAspNetCoreMvcUiThemeSharedModule),
        typeof(AbpAutoMapperModule)
        )]
    public class QuestionBankWebModule : AbpModule
    {
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
            {
                options.AddAssemblyResource(typeof(QuestionBankResource), typeof(QuestionBankWebModule).Assembly);
            });
        }

        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<AbpNavigationOptions>(options =>
            {
                options.MenuContributors.Add(new QuestionBankMenuContributor());
            });

            Configure<AbpVirtualFileSystemOptions>(options =>
            {
                options.FileSets.AddEmbedded<QuestionBankWebModule>("Topthink.Ruitu.QuestionBank.Web");
            });

            Configure<AbpAutoMapperOptions>(options =>
            {
                options.AddMaps<QuestionBankWebModule>(validate: true);
            });

            Configure<RazorPagesOptions>(options =>
            {
                options.Conventions.AuthorizePage("/Books/Index", QuestionBankPermissions.Books.Default);
                options.Conventions.AuthorizePage("/Books/CreateModal", QuestionBankPermissions.Books.Create);
                options.Conventions.AuthorizePage("/Books/EditModal", QuestionBankPermissions.Books.Edit);
            });

        }
    }
}
